"use strict";

function init() {
    var vm = new Vue({
        el: "#app",
        data: {
            formData: {
                tags: ''
            },

            dataList:[],
           
            hideLoadingToast: true,
            errorAlert: {
                hideErrorAlert: true,
                errMsg : "未知错误"
            }
        },
        methods: {
            detail(index) {
                var id = this.dataList[index].id
                 mm.go("../key-form/key-form.html?type=1&id=" + id);
            },
            add() {
                mm.go("../key-form/key-form.html?type=0")
            },
            submit() {
                if(!this.formData.tags) return;
                var _this = this;
                this.hideLoadingToast = false
                keyService.list(this.formData, function(data) {
                    _this.hideLoadingToast = true
                    _this.dataList = data.list;
                }, function(errMsg) {
                    _this.hideLoadingToast = true
                    _this.errorAlert.errMsg = errMsg;
                    _this.errorAlert.hideErrorAlert = false
                });
            },
            login() {
                mm.go("../login/login.html");
            },
            clear() {
                var _this = this;
                this.formData.tags = "";
                keyService.list({}, function(data) {
                    _this.hideLoadingToast = true
                    _this.dataList = data.list;
                }, function(errMsg) {
                    _this.hideLoadingToast = true
                    _this.errorAlert.errMsg = errMsg;
                    _this.errorAlert.hideErrorAlert = false
                });
            },
            hideAlert() {
                this.errorAlert.hideErrorAlert = true
            }
        },
        created() {
            this.clear()
        }
    })
}

init();